package com.moli.iov.open.web.controller;

import com.moli.iov.base.model.dto.req.VehicleFenceBindingReqOpDto;
import com.moli.iov.open.model.vo.req.VehicleFenceBindingListVo;
import com.moli.iov.open.model.vo.req.VehicleFenceBindingVo;
import com.moli.iov.open.model.vo.req.VehicleFenceVo;
import com.moli.iov.open.service.VehicleFenceBindingService;
import com.moli.iov.rest.RestResponse;
import com.moli.iov.util.CommonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 围栏绑定
 *
 * @author wanghualin
 * @date 2019-09-21 09:13:54
 */
@Slf4j
@RestController
@RequestMapping("/api/vehicleBinding")
public class VehicleFenceBindingController extends BaseController {

    @Autowired
    private VehicleFenceBindingService iVehicleFenceBindingService;

    /**
     * 添加围栏绑定车辆
     */
    @PostMapping("/save")
    public RestResponse saveVehicleFenceBinding(
            @Validated({VehicleFenceBindingVo.Save.class}) @RequestBody VehicleFenceBindingVo vo) {
        log.info("OP 添加围栏绑定车辆入参：{}", vo);
        assembleUserInfo(vo);
        VehicleFenceBindingReqOpDto dto = new VehicleFenceBindingReqOpDto();
        CommonUtils.copyProperties(vo, dto);

        return iVehicleFenceBindingService.saveVehicleFenceBinding(dto);
    }

    /**
     * 删除围栏绑定车辆
     */
    @PostMapping("/delete")
    public RestResponse deleteVehicleFenceBinding(
            @Validated({VehicleFenceBindingVo.Delete.class}) @RequestBody VehicleFenceBindingVo vo) {
        log.info("OP 删除围栏绑定车辆入参：{}", vo);
        assembleUserInfo(vo);
        VehicleFenceBindingReqOpDto dto = new VehicleFenceBindingReqOpDto();
        CommonUtils.copyProperties(vo, dto);
        return iVehicleFenceBindingService.deleteVehicleFenceBinding(dto);
    }

    /**
     * 删除车辆绑定所有围栏
     */
    @PostMapping("/deleteAll")
    public RestResponse deleteAllVehicleFenceBinding(
            @Validated({VehicleFenceBindingVo.DeleteAll.class}) @RequestBody VehicleFenceBindingVo vo) {
        log.info("OP 删除围栏绑定车辆入参：{}", vo);
        assembleUserInfo(vo);
        VehicleFenceBindingReqOpDto dto = new VehicleFenceBindingReqOpDto();
        CommonUtils.copyProperties(vo, dto);
        return iVehicleFenceBindingService.deleteAllVehicleFenceBinding(dto);
    }


    /**
     * 删除车辆绑定所有围栏
     */
    @PostMapping("/isInside")
    public RestResponse isVehicleInsideFence(@Validated({VehicleFenceBindingVo.Inside.class}) @RequestBody VehicleFenceBindingVo vo) {
        log.info("查询车是否在围栏内入参：{}", vo);
        assembleUserInfo(vo);
        VehicleFenceBindingReqOpDto dto = new VehicleFenceBindingReqOpDto();
        CommonUtils.copyProperties(vo, dto);
        return iVehicleFenceBindingService.isVehicleInsideFence(dto);
    }

    /**
     * 删除车辆绑定所有围栏
     */
    @PostMapping("/isInsides")
    public RestResponse isVehicleInsideFences(@Validated({VehicleFenceBindingVo.InsideList.class}) @RequestBody VehicleFenceBindingVo vo) {
        log.info("查询车是否在多个围栏内入参：{}", vo);
        assembleUserInfo(vo);
        VehicleFenceBindingReqOpDto dto = new VehicleFenceBindingReqOpDto();
        CommonUtils.copyProperties(vo, dto);
        return iVehicleFenceBindingService.isVehicleInsideFenceList(dto);
    }

    /*  *//**
     * 查询围栏与车辆的绑定关系
     *//*
  @PostMapping("/list")
  public RestRespons e deleteVehicleFenceBinding(
      @Validated({VehicleFenceBindingVo.Read.class}) @RequestBody VehicleFenceBindingVo vo) {
    assembleUserInfo(vo);
    VehicleFenceBindingReqOpDto dto = new VehicleFenceBindingReqOpDto();
    CommonUtils.copyProperties(vo, dto);
    return iVehicleFenceBindingService.deleteVehicleFenceBinding(dto);
  }*/


}
